a = {'zero': 0,
     'one': 1,
     'two': 2,
     'three': 3,
     'four': 4,
     'five': 5,
     'six': 6,
     'seven': 7,
     'eight': 8,
     'nine': 9
     }

w = input().split()
if w[0] in a and w[0] != 'zero' and w[1] in a and w[2] in a and len(w) == 3:
    c = int(str(a[w[0]]) + str(a[w[1]]) + str(a[w[2]]))
    z, x = 0, 0
    num1, num2 = c, c
    while num1 % 2 == 0 or num1 % 3 == 0 or num1 % 5 == 0 or num1 % 7 == 0:
        num1 += 1
        z += 1
    while num2 % 2 == 0 or num2 % 3 == 0 or num2 % 5 == 0 or num2 % 7 == 0:
        num2 -= 1
        x += 1
    if z < x:
        print(num1)
    else:
        print(num2)
else:
    print('Wrong input')
